package camid.test.testobjects;

import java.util.concurrent.Future;

import camid.distribution.activeobject.AsyncResult;

public class FutureIntegerBuffer implements IFutureIntegerBuffer {
	
	private Integer buffer;
	
	private static final AsyncResult<Void> result = new AsyncResult<Void>(null);
	
	@Override
	public Future<Void> set(Integer value) {
		buffer = value;
		return result;
	}

	@Override
	public Future<Integer> get() {
		return new AsyncResult<Integer>(buffer);
	}

	@Override
	public Future<Integer> getAndSet(Integer newValue) {
		Integer oldValue = buffer;
		buffer = newValue;
		return new AsyncResult<Integer>(oldValue);
	}

	@Override
	public Future<Integer> getAndIncrement() {
		Integer oldValue = buffer;
		buffer++;
		return new AsyncResult<Integer>(oldValue);
	}

	
}
